package edu.nf.exam.controller;

import edu.nf.exam.entity.QuestionContentInfo;
import edu.nf.exam.service.QuestionContentService;
import edu.nf.exam.service.impl.QuestionContentServiceImpl;
import org.nf.mvc.annotation.RequestMapping;
import org.nf.mvc.servlet.View;
import org.nf.mvc.view.JsonView;

/**
 * @Author : LLH
 * @create 2021/6/24
 */
public class QuestionContentController extends BaseController{
    /**
     * 添加
     * @param questionContentInfo
     * @return
     */
    @RequestMapping("/questionContent/add")
    public View add(QuestionContentInfo questionContentInfo){
        QuestionContentService service=new QuestionContentServiceImpl();
        try {
            service.checkAdd(questionContentInfo);
            // 主键生成策略：当完成添加操作后，返回主键（编号）的值
            Integer questionContentId = questionContentInfo.getQuestionContentId();

            return new JsonView(success(questionContentId));
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonView(fail(500,e.getMessage()));
        }
    }

    /**
     * 修改
     * @param questionContentInfo
     * @return
     */
    @RequestMapping("/questionContent/update")
    public View update(QuestionContentInfo questionContentInfo){
        QuestionContentService service=new QuestionContentServiceImpl();
        try {
            service.checkUpdate(questionContentInfo);

            return new JsonView(success("修改成功"));
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonView(fail(500,e.getMessage()));
        }
    }
}
